﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;

namespace Manager
{   
    public partial class SalaryReport : Form
    {
        SQL sql = new SQL();
        public SalaryReport()
        {
            InitializeComponent();
        }

        private void SalaryReport_Load(object sender, EventArgs e)
        {
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Salary cr = new Salary();
            cr.SetDataSource(sql.sql_report("sql_select_Baocao"));         

            ParameterFieldDefinitions crParameterFieldDefinitions;
            ParameterFieldDefinitions crParameterFieldDefinitions1;
            ParameterFieldDefinitions crParameterFieldDefinitions2;
               
            ParameterFieldDefinition crParameterFieldDefinition;
            ParameterFieldDefinition crParameterFieldDefinition1;
            ParameterFieldDefinition crParameterFieldDefinition2;
                
            ParameterValues crParameterValues = new ParameterValues();
            ParameterValues crParameterValues1 = new ParameterValues();
            ParameterValues crParameterValues2 = new ParameterValues();
               
            ParameterDiscreteValue crParameterDiscreteValue = new ParameterDiscreteValue();
            ParameterDiscreteValue crParameterDiscreteValue1 = new ParameterDiscreteValue();
            ParameterDiscreteValue crParameterDiscreteValue2 = new ParameterDiscreteValue();
                
            crParameterDiscreteValue.Value = dateTimePicker1.Value.ToShortDateString();
            crParameterDiscreteValue1.Value = dateTimePicker2.Value.ToShortDateString();
            crParameterDiscreteValue2.Value = textBox1.Text;
                
            crParameterFieldDefinitions = cr.DataDefinition.ParameterFields;
            crParameterFieldDefinitions1 = cr.DataDefinition.ParameterFields;
            crParameterFieldDefinitions2 = cr.DataDefinition.ParameterFields;
                
            crParameterFieldDefinition = crParameterFieldDefinitions["Ngày bắt đầu"];
            crParameterFieldDefinition1 = crParameterFieldDefinitions1["Ngày kết thúc"];
            crParameterFieldDefinition2 = crParameterFieldDefinitions2["Expr1"];
                
            crParameterValues = crParameterFieldDefinition.CurrentValues;
            crParameterValues1 = crParameterFieldDefinition1.CurrentValues;
            crParameterValues2 = crParameterFieldDefinition2.CurrentValues;
                
            crParameterValues.Clear();
            crParameterValues1.Clear();
            crParameterValues2.Clear();
                
            crParameterValues.Add(crParameterDiscreteValue);
            crParameterValues1.Add(crParameterDiscreteValue1);
            crParameterValues2.Add(crParameterDiscreteValue2);
          
            crParameterFieldDefinition.ApplyCurrentValues(crParameterValues);
            crParameterFieldDefinition1.ApplyCurrentValues(crParameterValues1);
            crParameterFieldDefinition2.ApplyCurrentValues(crParameterValues2);
               
            crystalReportViewer1.ReportSource = cr;
            crystalReportViewer1.Refresh();
        }
    }
}
